package com.improve.frame.log.service.impl;

import com.improve.frame.log.domain.SysLog;
import com.improve.frame.log.service.LogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

/**
 * @Description 日志实现类-打印日志
 * @Author wzxing918
 * @Date 2021-03-31
 * @Version 1.0.0
 **/
@Slf4j
@ConditionalOnProperty(name = "improve.log.log-type", havingValue = "logger", matchIfMissing = true)
public class LoggerServiceImpl implements LogService {

    private static final String MSG_PATTERN = "{}|{}|{}|{}|{}|{}|{}|{}";

    /**
     * 格式为：{模块名}|{请求路径}|{请求方法}|{请求参数}|{操作IP}|{操作名称}|{响应时间}|{操作时间}
     *
     * 例子用户管理|http://improve:6603/user/add|POST|dto: userDto(id=null, name=null)|192.168.125.10|admin|35|2020-02-04 09:13:34
     */
    @Override
    public void save(SysLog sysLog) {
        log.debug(MSG_PATTERN,
                sysLog.getModuleName(),
                sysLog.getRequestUrl(),
                sysLog.getRequestMethod(),
                sysLog.getRequestParam(),
                sysLog.getOperationIp(),
                sysLog.getOperatorName(),
                sysLog.getOperationTime(),
                sysLog.getCreateTime());
    }
}
